<?php
header("Content-type:text/html; charset=utf-8;");
require '../../../ppf/fun.php';
require '../../../ppf/pdo_mysql.php';
require '../../../ppf/Filter.php';
date_default_timezone_set("PRC");
$pd=new pdo_mysql();
$filter=new Filter();
session_start();
if(empty($_SESSION['uid'])){
	echo '请登录后再进行操作';exit;
}
$submitMethod=$_SERVER["REQUEST_METHOD"];
if($submitMethod=='POST'){
	$id          =empty($_POST['id'])?0:Filter::filter_number($_POST['id']);
	$release_user  = Filter::safe_string($_POST['name']);
	$agent       = Filter::safe_string($_POST['agent']);
	$deptname    =Filter::safe_string($_POST['deptname']);
	$contact_phone = $_POST['contact_phone'];
	$project_type = Filter::safe_string($_POST['project_type']);
	$takes_time = $_POST['takes_time'];
	$repair_type    = Filter::safe_string($_POST['repair_type']);
	$repair_user    =Filter::safe_string($_POST['repair_user']);
	$takes_addressr =Filter::safe_string($_POST['takes_address']);
    if(empty($repair_user)){
        $repair_user = "待指定";
    }
	$remark = Filter::safe_string($_POST['remark']);
	$in_data=array(
		'service_sn'=>date("YmdH").rand(1000,9999),
		'release_user' =>$release_user,
		'agent' =>$agent,
		'takes_type'=>$repair_type,
		'code'=>$remark,
		'takes_user'=>$repair_user,
		'contact_phone'=>$contact_phone,
		'release_time'=>date('Y-m-d H:i:s',time()),
		'takes_time'=>$takes_time,
		'project_type'=>$project_type,
        'release_user_id'=>$_SESSION['uid'],
        'department'=>$deptname,
		'takes_address'=>$takes_addressr
	);
	$result=0;
	$tps='';
	
	if($id==0){
		$result=$pd->insert(array('data'=>$in_data,'table'=>'sys_takes_list'));
	}else{
		$result=$pd->update(array('data'=>$in_data,'table'=>'sys_takes_list','where'=>"id=".$id));
	}
	
	//print_r($result);exit;
	if(empty($result)){
		$tps='操作失败,请重试';
	}else{
		//return '1';
		$tps='操作成功';
	}

	echo $tps;exit;
}else{
	echo "不允许的表单提交方式，请按正常流程提交表单。";exit;
}
?>